﻿<script type="text/javascript">
    var toolbar_danwei = [{
        text: '新增单位',
        iconCls: 'icon-add',
        handler: function() {
            $("#danwei-edit").dialog('open');
            $("#info-danweimingcheng").textbox('setValue', '');
            $("#info-danweileixing").combobox('setValue', '入库单位');
            $("#info-danweizhuangtai").combobox('setValue', '启用');
            $("#danWeiID").val('');
            $("#info-gongyingshang").combobox('setValue', '');
            $("#info-danweimingcheng").textbox('textbox').focus();
        }
    }, '-', {
        text: '修改单位',
        iconCls: 'icon-edit',
        handler: function() {
            var curRow = $("#xinxi_danwei").datagrid('getSelected');
            if (curRow) {
                $("#danWeiID").val(curRow.id);
                $("#danwei-edit").dialog('open');
                $("#info-danweimingcheng").textbox('setValue', curRow.danweimingcheng);
                $("#info-danweileixing").combobox('setValue', curRow.danweileixing);
                if (curRow.danweizhuangtai == "启用") {
                    $("#info-danweizhuangtai").combobox('setValue', '启用');
                }
                else {
                    $("#info-danweizhuangtai").combobox('setValue', '禁用');
                }
                $("#info-gongyingshang").combobox('setValue', curRow.gongyingshang);
                $("#info-danweimingcheng").textbox('textbox').focus();
            }
            else {
                alert("请选择要修改的单位信息。");
            }
        }
    }, '-', {
        text: '删除单位',
        iconCls: 'icon-remove',
        handler: function() {
            $("#danwei-dlg").dialog('open');
        }
}];

        function DelDanWei() {
            var curRow = $("#xinxi_danwei").datagrid('getSelected');
            if (curRow) {
                $.post('handler/xinxi_danwei.ashx', { danWeiType: "3", danWeiID: curRow.id ,uid:window.uid,kid:window.kid}, function(data, status) {
                    if (data == "OK") {
                        $("#danwei-dlg").dialog('close');
                        $("#xinxi_danwei").datagrid('load');
                        return;
                    }
                    if (data == "Failed") {
                        alert("删除单位信息失败，请重试");
                        $("#danwei-dlg").dialog('close');
                        return;
                    }
                    alert(data);
                    $("#danwei-dlg").dialog('close');
                });
            }
            else {
                alert("请选择要删除的单位信息。");
            }

        }
        function submitDanWeiForm() {
            var danweimingcheng = $("#info-danweimingcheng").textbox('getText');
            var danweileixing = $("#info-danweileixing").combobox('getText');
            var danweizhuangtai = $("#info-danweizhuangtai").combobox('getText');
            var danweiid = $("#danWeiID").val();
            var gongyingshang = $("#info-gongyingshang").combobox('getValue');
            var gongyingshangmingcheng = $("#info-gongyingshang").combobox('getText');
            if (danweileixing && danweimingcheng) {
                $.post("handler/xinxi_danwei.ashx", { uid: window.uid, kid: window.kid, danWeiID:danweiid,danWeiType:'2',danweimingcheng:danweimingcheng,danweileixing:danweileixing,danweizhuangtai:danweizhuangtai,gongyingshang:gongyingshang,gongyingshangmingcheng:gongyingshangmingcheng}, function (data, status) {
                    if (data == "OK") {
                        $("#danwei-edit").dialog('close');
                        $("#xinxi_danwei").datagrid('load');
                        return;
                    }
                    if (data == "Failed") {
                        alert("保存单位信息失败，请重试");
                        return;
                    }
                    alert(data);
                });
            }
            else {
                alert("信息不完整，请检查后重试。");
            }

        }

        function clearDanWeiForm() {
            $("#danwei-edit").dialog('close');
        }
        $.parser.onComplete = function () {
            $("#info-gongyingshang").combobox({
                valueField: 'id',
                textField: 'mingcheng',
                panelWidth: 200,
                panelHeight: 'auto',
                editable: false,
                url: 'handler/xinxi_gongyingshang.ashx',
                method: 'post',
                queryParams: { gongYingShangType: '4', uid: window.uid, kid: window.kid }
            });
            $("#xinxi_danwei").datagrid({
                url: 'handler/xinxi_danwei.ashx',
                method: 'post',
                queryParams: { danWeiType: '1' ,uid:window.uid,kid:window.kid}
            });
        }
</script>

<table id="xinxi_danwei" style="width:100%" class="easyui-datagrid" title="单位管理" data-options="border:false,singleSelect:true,collapsible:false,striped:true,toolbar:toolbar_danwei">
    <thead>
        <tr>
            <th data-options="field:'danweimingcheng',width:200">
                单位名称
            </th>
            <th data-options="field:'danweileixing',width:100">
                单位类型
            </th>
            <th data-options="field:'danweizhuangtai',width:100">
                单位状态
            </th>
            <th data-options="field:'gongyingshangmingcheng',width:200">
                供应商名称
            </th>
            <th data-options="field:'id',hidden:true">
                编号
            </th>
            <th data-options="field:'gongyingshang',hidden:true">
                供应商编号
            </th>
        </tr>
    </thead>
</table>


<div id="danwei-edit" class="easyui-dialog" title="单位信息编辑" data-options="modal:true,closed:true,iconCls:'icon-edit',draggable:false,collapsible:false,minimizable:false,maximizable:false,resizable:false"
    style="width: 500px; height: 260px; padding: 10px;">
    <div style="width: 350px; margin: 0 auto;">
        <table cellpadding="5" style="font-size: 13px; margin: 0 auto; padding-top: 20px">
            <tr>
                <td>
                    单位名称:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info-danweimingcheng" name="info-danweimingcheng"
                        data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    单位类型:
                </td>
                <td>
                    <select class="easyui-combobox" name="info-danweileixing" id="info-danweileixing"
                        data-options="width:200, panelHeight: 'auto',editable:false">
                        <option value="入库单位">入库单位</option>
                        <option value="出库单位">出库单位</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    状态:
                </td>
                <td>
                    <select class="easyui-combobox" name="info-danweizhuangtai" id="info-danweizhuangtai"
                        data-options="width:200, panelHeight: 'auto',editable:false">
                        <option value="启用">启用</option>
                        <option value="禁用">禁用</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    供应商:
                </td>
                <td>
                    <select class="easyui-combobox" name="info-gongyingshang" id="info-gongyingshang"
                            data-options="width:200, panelHeight: 'auto',editable:false">
                    </select>
                </td>
            </tr>
        </table>
        <input type="hidden" name="danWeiID" id="danWeiID" value="" />
        <div style="text-align: center; padding: 5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="submitDanWeiForm()"
                data-options="iconCls:'icon-ok'">保存</a> <a href="javascript:void(0)" class="easyui-linkbutton"
                    style="width: 75px" onclick="clearDanWeiForm()" data-options="iconCls:'icon-cancel'">关闭</a>
        </div>
    </div>
</div>

<div id="danwei-dlg" class="easyui-dialog" title="删除确认" style="width: 300px; height: 150px;
    padding: 10px" data-options="iconCls: 'icon-help',buttons: '#danwei-dlg-buttons',modal:true,closed:true">
    确定要删除该单位信息吗？
</div>
<div id="danwei-dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:DelDanWei();">
        确定</a> 
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#danwei-dlg').dialog('close');">
            取消</a>
</div>
